﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OnGroundSensor : MonoBehaviour
{
    public float offset = 0.3f;

    public CapsuleCollider capCol;
    private Vector3 point0;
    private Vector3 point1;
    private float radius;
    private float height;

    // Start is called before the first frame update
    void Awake()
    {
        //capCol = gameObject.GetComponentInParent<CapsuleCollider>();
        radius = capCol.radius;
        height = capCol.height;
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        point0 = transform.position + transform.up * (radius-offset);
        point1 = transform.position + transform.up * (height - offset) - transform.up * radius;
        Collider[] outputCols = Physics.OverlapCapsule(point0, point1, radius, LayerMask.GetMask("Ground"));
        if (outputCols.Length>0) {
            gameObject.SendMessageUpwards("IsGround");
        }
        else {
            gameObject.SendMessageUpwards("IsNotGround");
        }

    }
}
